home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDTrack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.6 KB  |  186 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDTrack - An XFCN to report the number of tracks
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDTrack.c
  11.     link -sn Main=CDTrack -sn STDIO=CDTrack ∂
  12.          -sn INTENV=CDTrack -rt XFCN=42 ∂
  13.          -m CDTrack CDTrack.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    ATrack(short, short *);
  28. OSErr    ReadQ(short, short *, short *, short *, short *);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDTrack
  36.  *
  37.  *  Purpose:        return the number of tracks on this disc.
  38.  *
  39.  *  Returns:        either the number of tracks, or an error
  40.  *                    if it's a negative number, it's an error
  41.  *
  42.  *  Side Effects:
  43.  *
  44.  *  Description:    We need no parameter:
  45.  *                    Get the ioRefNum that we got from previously calling
  46.  *                    CDOpen() from accessing a famous global.
  47.  *                    call the driver with a READTOC call to find out
  48.  *                    how many tracks there are.
  49.  *
  50.  ************************************************************************/
  51. pascal void
  52. CDTrack(paramPtr)
  53. XCmdBlockPtr    paramPtr;
  54. {
  55.     Str31    returnString;
  56.     OSErr    result;
  57.     short    ioRefNum;
  58.     Handle    refHandle;
  59.     short    numberTracks;
  60.     short    trackNo, minute, second, block;
  61.     long    args[2];
  62.     
  63.     /* Must be no parameter */
  64.     if ((paramPtr->paramCount) != 0)
  65.     {
  66.         /* Report error in parameters by returning -1 */
  67.         NumToStr(paramPtr, (long) -1, &returnString);
  68.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  69.         return;
  70.     }
  71.     
  72.     /* Get the global ioRefNum and convert it. */
  73.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  74.     ioRefNum = atoi(*(refHandle));
  75.     DisposHandle(refHandle);
  76.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  77.     
  78.     result = ATrack(ioRefNum, &numberTracks);
  79.     
  80.     if (result == noErr)
  81.         result = ReadQ(ioRefNum, &trackNo, &minute, &second, &block);
  82.  
  83.     if (result == noErr)
  84.     {
  85.         args[0] = (long) trackNo;
  86.         args[1] = (long) numberTracks;
  87.         FormatString(&returnString, args, (long) 2);
  88.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  89.     }
  90.     else
  91.     {
  92.         /* We got an error. Convert result to string & return it as error */
  93.         NumToStr(paramPtr, (long) result, &returnString);
  94.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  95.     }
  96. }
  97.  
  98. /************************************************************************
  99.  *
  100.  *  Function:        ATrack
  101.  *
  102.  *  Purpose:        report how many tracks are on this CD
  103.  *
  104.  *  Returns:        OSErr.  Probably either
  105.  *                        noErr        everything's hunky-dory!
  106.  *                        paramErr    you messed up the call somehow.
  107.  *
  108.  *  Side Effects:    none
  109.  *
  110.  *  Description:    Simply call the driver.
  111.  *
  112.  ************************************************************************/
  113. OSErr
  114. ATrack(refNum, numberTracks)
  115. short    refNum;
  116. short    *numberTracks;
  117. {
  118.     CDParam    myPB;
  119.     OSErr    result;
  120.     
  121.     myPB.ioCompletion = 0;
  122.     myPB.ioNamePtr = (char *) 0;
  123.     myPB.ioVRefNum = 1;
  124.     myPB.ioCRefNum = refNum;
  125.     myPB.csCode = READTOC;
  126.     myPB.csParam[0] = 0;
  127.     myPB.csParam[1] = 1;
  128.     
  129.     result = PBControl(&myPB, false);
  130.     
  131.     if (result == noErr)
  132.         *numberTracks = (short) BCD2DECIMAL(myPB.csParam[1]);
  133.     return result;
  134. }
  135.  
  136.  
  137. /************************************************************************
  138.  *
  139.  *  Function:        ReadQ
  140.  *
  141.  *  Purpose:        return current Q subcode address data
  142.  *
  143.  *  Returns:        OSErr.  Probably either
  144.  *                        noErr        everything's hunky-dory!
  145.  *                        paramErr    you messed up the call somehow.
  146.  *
  147.  *  Side Effects:    none
  148.  *
  149.  *  Description:    Simply call the driver.  Return track number and
  150.  *                    absolute minute, second, block.
  151.  *
  152.  ************************************************************************/
  153. OSErr
  154. ReadQ(refNum, trackNo, minute, second, block)
  155. short    refNum;
  156. short    *trackNo;
  157. short    *minute;
  158. short    *second;
  159. short    *block;
  160. {
  161.     CDParam    myPB;
  162.     OSErr    result;
  163.     
  164.     myPB.ioCompletion = 0;
  165.     myPB.ioNamePtr = (char *) 0;
  166.     myPB.ioVRefNum = 1;
  167.     myPB.ioCRefNum = refNum;
  168.     myPB.csCode = READQ;
  169.     
  170.     result = PBControl(&myPB, false);
  171.     
  172.     if (result == noErr)
  173.     {
  174.         *trackNo = (short) BCD2DECIMAL(myPB.csParam[1]);
  175.         *minute = (short) BCD2DECIMAL(myPB.csParam[6]);
  176.         *second = (short) BCD2DECIMAL(myPB.csParam[7]);
  177.         *block = (short) BCD2DECIMAL(myPB.csParam[8]);
  178.     }
  179.     return result;
  180. }
  181.  
  182.  
  183.  
  184. /* C routines for HyperCard callbacks */
  185. #include <XCmdGlue.inc.c>
  186.